package top.kent90.controller;

import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.support.Parameter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import top.kent90.common.object.AjaxDone;
import top.kent90.common.object.Result;
import top.kent90.service.SysUserService;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("sysUser")
public class SysUserController {
    @Reference
    SysUserService service;
    @RequestMapping("toAddSysUser")
    public String toAddSysUser(){return "sysUser/addSysUser";}


    /**
     * 用户列表
     * @param request
     * @return
     */
    @RequestMapping("sysUserList")
    @ResponseBody
    public Result sysList(HttpServletRequest request){
        String userName = request.getParameter("userName");
        String status = request.getParameter("status");
        String identity = request.getParameter("identity");
        //获取页码
        String pageNum = request.getParameter("page");
        //获取显示条数
        String pageSize = request.getParameter("limit");
        Map<String,Object> map = new HashMap<>();
        map.put("userName",userName);
        map.put("status",status);
        map.put("identity",identity);
        Result rs = service.querySysUser(map,pageNum,pageSize);
        return rs;
    }
    /**
     * 设置角色
     */
    @RequestMapping("toSetRoles")
    @ResponseBody
    public ModelAndView toSetRoles(@ModelAttribute("userId") String userId ){
        List<Map<String,Object>>list = service.queryRoles(userId);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sysuser/setRoles");
        modelAndView.addObject("data",list);
        return modelAndView;
    }
    @RequestMapping("addsysUser")
    @ResponseBody
    public AjaxDone addSysUser(){

        return new AjaxDone("200","添加成功");
    }
}
